home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / arp.p < prev    next >
Text File  |  1993-12-28  |  62KB  |  1,961 lines

  1.  
  2. /* Address Resolution Protocol (ARP) functions. Sits between IP and
  3.  * Level 2, mapping IP to Level 2 addresses for all outgoing datagrams.
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6.  
  7. /****************************************************************************
  8. *    $Id: arp.c 1.2 93/07/16 11:41:45 ROOT_DOS Exp $
  9. *    14 Jun 93    1.2        GT    Fix warnings.                                    *
  10. *
  11. *  ATARI Version by David Nash - dnash@chaos.demon.co.uk
  12. *
  13. *  ANSI style function definitions
  14. *
  15. ****************************************************************************/
  16.  
  17. /****************************************************************************
  18. *    $Id: global.h 1.6 93/07/16 11:44:56 ROOT_DOS Exp $
  19. *    24 Aug 92    1.3        GT    Redefine time.                                    *
  20. *    13 Sep 92    1.4        GT    New file modes.                                    *
  21. *    09 May 93    1.6        GT    Fix warnings.                                    *
  22. *
  23. *  ATARI Version by David Nash - dnash@chaos.demon.co.uk
  24. *
  25. *  stdio.h and stdlib included
  26. *  shadow definitions added for fileops
  27. ****************************************************************************/
  28.  
  29. /* Global definitions used by every source file.
  30.  * Some may be compiler dependent.
  31.  */
  32.  
  33. /**
  34.  * $Id: stdio.h,v 1.1 1993/11/14 14:43:52 AGK Rel $
  35.  *
  36.  * ANSI I/O interface file
  37.  *
  38.  * (c) Copyright 1989, 1992, 1993 HiSoft
  39. **/
  40.  
  41. /**
  42.  * $Id: __types.h,v 1.1 1993/11/14 14:42:42 AGK Rel $
  43.  *
  44.  * Library type definitions
  45.  *
  46.  * (c) Copyright 1992, 1993 HiSoft
  47. **/
  48.  
  49. /* ANSI X3.159-1989 types */
  50. typedef long __clock_t;
  51. typedef long int __ptrdiff_t;
  52. typedef unsigned long __size_t;
  53. typedef long __time_t;
  54. typedef unsigned char __wchar_t;
  55. typedef char *__va_list;
  56.  
  57. /* ISO/IEC 9945-1:1990 types */
  58. typedef long __off_t;
  59. typedef short __nlink_t;
  60. typedef short __pid_t;
  61. typedef signed long __ssize_t;
  62. typedef unsigned short __dev_t;
  63. typedef unsigned short __gid_t;
  64. typedef unsigned short __mode_t;
  65. typedef unsigned short __uid_t;
  66. typedef unsigned long __ino_t;
  67. typedef unsigned long __sigset_t;
  68.  
  69. typedef __size_t size_t;
  70. long __regargs _CXCERR(long);        /* always __regargs for efficiency */
  71.  
  72. typedef unsigned long fpos_t;
  73.  
  74. /**
  75. *
  76. * Definitions associated with _iobuf._flag
  77. *
  78. **/
  79.  
  80. typedef struct _iobuf {
  81.     struct _iobuf *_next;
  82.     unsigned char *_ptr;    /* current buffer pointer */
  83.     int _rcnt;                /* current byte count for reading */
  84.     int _wcnt;                /* current byte count for writing */
  85.     unsigned char *_base;    /* base address of I/O buffer */
  86.     int _size;                /* size of buffer */
  87.     int _flag;                /* control flags */
  88.     int _file;                /* file descriptor */
  89.     unsigned char _cbuff;    /* single char buffer */
  90. } FILE;
  91.  
  92. extern struct _iobuf _iob[];
  93.  
  94. /*
  95.  * Prototypes for ANSI standard functions.
  96.  */
  97. int rename(const char *,const char *);
  98. long _lgscc(int,int,const char *,const char *);
  99. int remove(const char *);
  100. long _lgc(int,const char *);
  101. FILE *tmpfile(void);
  102. char *tmpnam(char *s);
  103.  
  104. int fclose(FILE *);
  105. int fflush(FILE *);
  106. FILE *fopen(const char *, const char *);
  107. FILE *freopen(const char *, const char *, FILE *);
  108. void setbuf(FILE *, char *);
  109. int setvbuf(FILE *, char *, int, size_t);
  110.  
  111. int fprintf(FILE *, const char *, ...);
  112. int fscanf(FILE *, const char *, ...);
  113. int printf(const char *, ...);
  114. int lprintf(const char *, ...);
  115. int scanf(const char *, ...);
  116. int sprintf(char *, const char *, ...);
  117. int sscanf(const char *, const char *, ...);
  118. int vfprintf(FILE *, const char *, char *);
  119. int vprintf(const char *, char *);
  120. int vsprintf(char *, const char *, char *);
  121.  
  122. int __builtin_printf(const char *, ...);
  123. int fgetc(FILE *);
  124. char *fgets(char *, int, FILE *);
  125. int fputc(int, FILE *);
  126. int fputs(const char *, FILE *);
  127. int getc(FILE *);
  128. int getchar(void);
  129. char *gets(char *);
  130. int putc(int, FILE *);
  131. int putchar(int);
  132. int puts(const char *);
  133. int ungetc(int, FILE *);
  134.  
  135. size_t fread(void *, size_t, size_t, FILE *);
  136. size_t fwrite(const void *, size_t, size_t, FILE *);
  137. int fgetpos(FILE *, fpos_t *);
  138. int fseek(FILE *, long int, int);
  139. int fsetpos(FILE *, const fpos_t *);
  140. long int ftell(FILE *);
  141. void rewind(FILE *);
  142. void clearerr(FILE *);
  143. int feof(FILE *);
  144. int ferror(FILE *);
  145. void perror(const char *);
  146.  
  147. /*
  148.  * Prototypes for Non-ANSI functions.
  149.  */
  150. int fcloseall(void);
  151. FILE *fdopen(int, const char *);
  152. int fgetchar(void);
  153. int fileno(FILE *);
  154. int flushall(void);
  155. void fmode(FILE *, int);
  156. int __stdargs _writes(char *);
  157. int _tinyprintf(char *, ...);
  158. int fputchar(int);
  159. int setnbf(FILE *);
  160. int __flushbuff(int, FILE *);
  161. FILE *fopene(const char *, const char *,char *);
  162.  
  163. FILE *popen(const char *,const char *);
  164. int    pclose(FILE *);
  165.  
  166. extern int sys_nerr;
  167. extern const char *sys_errlist[];
  168.  
  169. int unlink(const char *);
  170. char *mktemp(char *s);
  171. short fputw(int,FILE *);
  172. long fputl(long,FILE *);
  173. short fgetw(FILE *);
  174. long fgetl(FILE *);
  175.  
  176. int __getbuff(FILE *);
  177.  
  178. extern int __fmask;
  179. extern int __fmode;
  180. extern int _bufsiz;        /* default file buffer size */
  181.  
  182. /**
  183.  * $Id: stdlib.h,v 1.1 1993/11/14 14:43:52 AGK Rel $
  184.  *
  185.  * General utilities and defines
  186.  *
  187.  * (c) Copyright 1989, 1993 HiSoft
  188. **/
  189.  
  190. typedef unsigned char wchar_t;
  191. extern char __mb_cur_max;
  192.  
  193. typedef struct
  194. {
  195.     int quot;
  196.     int rem;
  197. } div_t;
  198.  
  199. typedef struct
  200. {
  201.     long int quot;
  202.     long int rem;
  203. } ldiv_t;
  204.  
  205. void *malloc(size_t);
  206. void *calloc(size_t,size_t);
  207. void *realloc(void *, size_t);
  208. void free(void *);
  209.  
  210. void *getml(size_t);
  211. int rlsml(void *, size_t);
  212. size_t sizmem(void);
  213. size_t chkml(void);
  214.  
  215. void *getmem(unsigned);
  216. int rlsmem(void *, unsigned);
  217.  
  218. void *alloca(size_t);
  219.  
  220. extern size_t _stkdelta;    /* stack/data area separation chicken factor */
  221.  
  222. void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
  223. void dqsort(double *,size_t);
  224. void fqsort(float *,size_t);
  225. void lqsort(long *,size_t);
  226. void sqsort(short *,size_t);
  227. void tqsort(char **,size_t);
  228.  
  229. int mblen(const char *,size_t);
  230. size_t mbstowcs(wchar_t *, const char *, size_t);
  231. int mbtowc(wchar_t *, const char *, size_t);
  232. size_t wcstombs(char *, const wchar_t *, size_t);
  233. int wctomb(char *, wchar_t);
  234.  
  235. void exit(int);
  236. void abort(void);
  237. int atoi(const char *);
  238. double atof(const char *);
  239. long int atol(const char *);
  240. char *getenv(const char *);
  241.  
  242. void _exit(int);
  243. void _XCEXIT(int);
  244. char *argopt(int, const char *[], const char *, int *, char *);
  245.  
  246. void *bsearch(const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
  247.  
  248. void *lsearch(const void *, void *, size_t *, size_t, int (*)(const void *, const void *));
  249. void *lfind(const void *, const void *, const size_t *, size_t, int (*)(const void *, const void *));
  250.  
  251. int system(const char *);
  252. size_t _hash(const char *);
  253.  
  254. int abs(int);
  255. int __builtin_abs(int);
  256. int iabs(int);
  257. int __builtin_abs(int);
  258. long labs(long);
  259. long __builtin_labs(long);
  260. int min(int,int);
  261. int __builtin_min(int,int);
  262. int max(int,int);
  263. int __builtin_max(int,int);
  264. char *ecvt(double, int, int *, int *);
  265. char *fcvt(double, int, int *, int *);
  266. char *gcvt(double, int, char *);
  267. long getfnl(const char *, char *, size_t, int);
  268. int onexit(int(*)(int));
  269. int putenv(char *);
  270.  
  271. int rand(void);
  272. int rmvenv(const char *);
  273. void srand(unsigned int);
  274. double strtod(const char *, char **);
  275. long int strtol(const char *, char **, int);
  276. unsigned long int strtoul(const char *,char **,int);
  277. long int utpack(const char *);
  278. void utunpk(long int, char *);
  279.  
  280. int atexit(void (* )(void));
  281. div_t div(int, int);
  282. ldiv_t ldiv(long int, long int);
  283.  
  284. unsigned long _lrotl(unsigned long,int);
  285. unsigned short _rotl(unsigned int,int);
  286. unsigned long _lrotr(unsigned long,int);
  287. unsigned short _rotr(unsigned int,int);
  288. extern char *optarg;
  289. extern int optopt;
  290. extern int optind;
  291. extern int opterr;
  292. int getopt(int, char *const *, const char *);
  293.  
  294. /* These compilers require special open modes when reading binary files.
  295.  *
  296.  * "The single most brilliant design decision in all of UNIX was the
  297.  * choice of a SINGLE character as the end-of-line indicator" -- M. O'Dell
  298.  *
  299.  * "Whoever picked the end-of-line conventions for MS-DOS and the Macintosh
  300.  * should be shot!" -- P. Karn's corollary to O'Dells' declaration
  301.  */
  302. /* These two lines assume that your compiler's longs are 32 bits and
  303.  * shorts are 16 bits. It is already assumed that chars are 8 bits,
  304.  * but it doesn't matter if they're signed or unsigned.
  305.  */
  306. typedef long int32;                                /* 32-bit signed integer     */
  307. typedef unsigned short int16;                    /* 16-bit unsigned integer */
  308. typedef unsigned char byte_t;                    /*  8-bit unsigned integer */
  309. /* The "interrupt" keyword is non-standard, so make it configurable */
  310. /* Note that these definitions are on by default if none of the Turbo-C style
  311.  * memory model definitions are on; this avoids having to change them when
  312.  * porting to 68K environments.
  313.  */
  314. /* Since not all compilers support structure assignment, the ASSIGN()
  315.  * macro is used. This controls how it's actually implemented.
  316.  */
  317. /* Define null object pointer in case stdio.h isn't included */
  318. /* standard boolean constants */
  319. /* string equality shorthand */
  320. /* Extract a short from a long */
  321. /* Extract a byte from a short */
  322. /* Extract nibbles from a byte */
  323. /* Various low-level and miscellaneous functions */
  324. unsigned long availmem (void);
  325. void *callocw (unsigned nelem,unsigned size);
  326. int32 clock();
  327. int dirps (void);
  328. int htoi (char *);
  329. long htol (char *);
  330. char *inbuf (int16 port,char *buf,int16 cnt);
  331. int16 hash_ip (int32 addr);
  332. int istate (void);
  333. void log (int s,char *fmt, ...);
  334. int log2 (int16 x);
  335. void *ltop (long);
  336. void *mallocw (unsigned nb);
  337. char *outbuf (int16 port,char *buf,int16 cnt);
  338. long ptol (void *);
  339. void restore (int);
  340. void rflush (void);
  341. void rip (char *);
  342. char *smsg (char *msgs[],unsigned nmsgs,unsigned n);
  343. int tprintf (char *fmt,...);
  344. char *strdup (const char *);
  345. int wildmat (char *s,char *p,char **argv);
  346. /**
  347.  * $Id: time.h,v 1.1 1993/11/14 14:43:52 AGK Rel $
  348.  *
  349.  * ANSI/POSIX.1 Date and Time definitions
  350.  *
  351.  * (c) Copyright 1993 HiSoft
  352. **/
  353.  
  354. typedef    __clock_t clock_t;
  355. typedef    __time_t time_t;
  356. struct tm {
  357.     int tm_sec;
  358.     int tm_min;
  359.     int tm_hour;
  360.     int tm_mday;
  361.     int tm_mon;
  362.     int tm_year;
  363.     int tm_wday;
  364.     int tm_yday;
  365.     int tm_isdst;
  366. };
  367.  
  368. clock_t (clock)(void);
  369. double (difftime)(time_t, time_t);
  370. time_t (mktime)(struct tm *);
  371. time_t (time)(time_t *);
  372.  
  373. char *(asctime)(const struct tm *);
  374. char *(ctime)(const time_t *);
  375. struct tm *(gmtime)(const time_t *);
  376. struct tm *(localtime)(const time_t *);
  377. size_t (strftime)(char *, size_t, const char *, const struct tm *);
  378.  
  379. extern char *__tzname[2];
  380. extern int __daylight;
  381. extern long int __timezone;
  382. void (__tzset)(void);
  383.  
  384. void (tzset)(void);
  385. extern char *(tzname)[2];
  386. void (getclk)(unsigned char *);
  387. int (chgclk)(unsigned const char *);
  388. void (utunpk)(long, char *);
  389. long (utpack)(const char *);
  390. int (stime)(const time_t *);
  391. time_t ka9q_time (time_t *t);
  392.  
  393. /**
  394.  * $Id: stdlib.h,v 1.1 1993/11/14 14:43:52 AGK Rel $
  395.  *
  396.  * General utilities and defines
  397.  *
  398.  * (c) Copyright 1989, 1993 HiSoft
  399. **/
  400.  
  401. /**
  402.  * $Id: string.h,v 1.1 1993/11/14 14:43:52 AGK Rel $
  403.  *
  404.  * String and memory operations interface file
  405.  *
  406.  * (c) Copyright 1989, 1993 HiSoft
  407. **/
  408.  
  409. extern char _SLASH;        /* path separator character */
  410.  
  411. /*
  412.  *
  413.  * External definitions for string services
  414.  *
  415.  */
  416. char *strcat(char *, const char *);
  417. char *strchr(const char *, int);
  418. int strcmp(const char *, const char *);
  419. char *strcpy(char *, const char *);
  420. size_t strcspn(const char *, const char *);
  421. size_t strspn(const char *, const char *);
  422. size_t strlen(const char *);
  423. char *strncat(char *, const char *, size_t);
  424. int strncmp(const char *, const char *, size_t);
  425. char *strncpy(char *, const char *, size_t);
  426. char *strpbrk(const char *, const char *);
  427. char *strrchr(const char *, int);
  428. char *strstr(const char *, const char *);
  429. char *strtok(char *, const char *);
  430. char *strerror(int);
  431. int strcoll(const char *, const char *);
  432. size_t strxfrm(char *, const char *, size_t);
  433.  
  434. size_t __builtin_strlen(const char *);
  435. char *__builtin_strcpy(char *, const char *);
  436. int __builtin_strcmp(const char *, const char *);
  437.  
  438. size_t stcarg(const char *, const char *);
  439. size_t stccpy(char *to, const char *from, size_t length);
  440. char *stpcpy(char *, const char *);
  441. char *strdup(const char *);
  442. void strins(char *, const char *);
  443. char *strnset(char *, int, size_t);
  444. char *strrev(char *);
  445. size_t stcis(const char *, const char *);
  446. size_t stcisn(const char *, const char *);
  447. size_t stcpm(const char *, const char *, char **);
  448. size_t stcpma(const char *, const char *);
  449. char *stpblk(const char *);
  450. char *stpbrk(const char *, const char *);
  451. char *stpchr(const char *, int);
  452. char *stpsym(const char *, char *, size_t);
  453. char *stpchrn(const char *, int);
  454. char *stptok(const char *, char *, size_t, const char *);
  455. long strbpl(char **, size_t, const char *);
  456.  
  457. int stcgfe(char *, const char *);
  458. int stcgfn(char *, const char *);
  459. int stcd_i(const char *, int *);
  460. int stcd_l(const char *, long *);
  461. int stch_i(const char *, int *);
  462. int stch_l(const char *, long *);
  463. int stco_i(const char *, int *);
  464. int stco_l(const char *, long *);
  465. int stci_d(char *, int);
  466. int stci_h(char *, int);
  467. int stci_o(char *, int);
  468. int stcl_d(char *, long);
  469. int stcl_h(char *, long);
  470. int stcl_o(char *, long);
  471. int stcsma(char *, char *);
  472. int stcu_d(char *, unsigned);
  473. int stcul_d(char *, unsigned long);
  474.  
  475. size_t stclen(const char *);
  476. char *stpdate(char *, int, const char *);
  477. char *stptime(char *, int, const char *);
  478.  
  479. int strmid(const char *, char *, size_t, size_t);
  480. char *strlwr(char *);
  481. void strmfe(char *, const char *, const char *);
  482. void strmfn(char *, const char *, const char *, const char *, const char *);
  483. void strmfp(char *, const char *, const char *);
  484. int stcgfp(char *, const char *);
  485.  
  486. int strnicmp(const char *, const char *, size_t);
  487. int stricmp(const char *, const char *);
  488.  
  489. char *strset(char *, int);
  490. void strsfn(const char *, char *, char *, char *, char *);
  491. char *strupr(char *);
  492. int stspfp(char *, int *);
  493. void strsrt(char *[], size_t);
  494.  
  495. char *index(const char *, int);
  496. char *rindex(const char *, int);
  497. void swab(const void *,void *,size_t);
  498. /*
  499.  *
  500.  * External definitions for memory block services
  501.  *
  502.  */
  503. void *memchr(const void *, int, size_t);
  504. int memcmp(const void *, const void *, size_t);
  505. void *memcpy(void *, const void *, size_t);
  506. void *memmove(void *, const void *, size_t);
  507. void *memset(void *, int, size_t);
  508.  
  509. void *__builtin_memset(void *, int, size_t);
  510. int __builtin_memcmp(const void *, const void *, size_t);
  511. void *__builtin_memcpy(void *, const void *, size_t);
  512.  
  513. void bzero(void *, size_t);
  514. void bcopy(const void *, void *, size_t);
  515. int bcmp(const void *, const void *, size_t);
  516.  
  517. void *memccpy(void *, const void *, int, size_t);
  518. void *memswp(void *, void *, size_t);
  519. void *memrep(void *, const void *, size_t, size_t);
  520.  
  521. void setmem(void *, unsigned, int);
  522. void movmem(const void *, void *, unsigned);
  523. void repmem(const void *, void *, unsigned, unsigned);
  524. void swmem(void *, void *, unsigned);
  525. /* General purpose function macros already defined in turbo C */
  526. /* Externals used by getopt */
  527. extern int optind;
  528. extern char *optarg;
  529.  
  530. /* Threshold setting on available memory */
  531. extern int32 Memthresh;
  532.  
  533. /* System clock - count of ticks since startup */
  534. extern int32 Clock;
  535.  
  536. /* Various useful standard error messages */
  537. extern char Badhost[];
  538. extern char Nospace[];
  539. extern char Notval[];
  540. extern char *Hostname;
  541. extern char Version[];
  542.  
  543. /* Your system's end-of-line convention */
  544. extern char Eol[];
  545.  
  546. /* connect () failure timeout value. */
  547.  
  548. extern int32 connect_wait_val;
  549.  
  550. extern void (*Gcollect[])();
  551.  
  552. FILE *fopenx(const char *, const char *);
  553.  
  554. int    removex(const char *);
  555.  
  556. int    renamex(const char *, const char *);
  557.  
  558. int    openx(const char *, int, int);
  559.  
  560. int    creatx(const char *, int);
  561.  
  562. int    unlinkx(const char *);
  563.  
  564. int    accessx(const char *, int);
  565.  
  566. int    mkdirx(const char *);
  567.  
  568. /**
  569.  * $Id: stdio.h,v 1.1 1993/11/14 14:43:52 AGK Rel $
  570.  *
  571.  * ANSI I/O interface file
  572.  *
  573.  * (c) Copyright 1989, 1992, 1993 HiSoft
  574. **/
  575.  
  576. extern unsigned Ibufsize;    /* Size of interrupt buffers to allocate */
  577. extern int Nibufs;        /* Number of interrupt buffers to allocate */
  578.  
  579. /* Basic message buffer structure */
  580. struct mbuf {
  581.     struct mbuf *next;    /* Links mbufs belonging to single packets */
  582.     struct mbuf *anext;    /* Links packets on queues */
  583.     int16 size;        /* Size of associated data buffer */
  584.     int refcnt;        /* Reference count */
  585.     struct mbuf *dup;    /* Pointer to duplicated mbuf */
  586.     char *data;        /* Active working pointers */
  587.     int16 cnt;
  588. };
  589. /* In mbuf.c: */
  590. struct mbuf *alloc_mbuf (int16 size);
  591. struct mbuf *free_mbuf (struct mbuf *bp);
  592.  
  593. struct mbuf *ambufw (int16 size);
  594. struct mbuf *copy_p (struct mbuf *bp,int16 cnt);
  595. int16 dup_p (struct mbuf **hp,struct mbuf *bp,int16 offset,int16 cnt);
  596. struct mbuf *free_p (struct mbuf *bp);
  597. int16 len_p (struct mbuf *bp);
  598. void trim_mbuf (struct mbuf **bpp,int16 length);
  599. int write_p (FILE *fp,struct mbuf *bp);
  600.  
  601. struct mbuf *dequeue (struct mbuf **q);
  602. void enqueue (struct mbuf **q,struct mbuf *bp);
  603. void free_q (struct mbuf **q);
  604. int16 len_q (struct mbuf *bp);
  605.  
  606. struct mbuf *qdata (char *data,int16 cnt);
  607. int16 dqdata (struct mbuf *bp,char *buf,unsigned cnt);
  608.  
  609. void append (struct mbuf **bph,struct mbuf *bp);
  610. struct mbuf *pushdown (struct mbuf *bp,int16 size);
  611. int16 pullup (struct mbuf **bph,char *buf,int16 cnt);
  612.  
  613. int pullchar (struct mbuf **bpp);       /* returns -1 if nothing */
  614. long pull16 (struct mbuf **bpp);    /* returns -1 if nothing */
  615. int32 pull32 (struct mbuf **bpp);    /* returns  0 if nothing */
  616.  
  617. int16 get16 (char *cp);
  618. int32 get32 (char *cp);
  619. char *put16 (char *cp,int16 x);
  620. char *put32 (char *cp,int32 x);
  621.  
  622. void iqstat (void);
  623. void refiq (void);
  624. void mbuf_crunch (struct mbuf **bpp);
  625.  
  626. /****************************************************************************
  627. *    timer.h                                                                    *
  628. *    $Id: timer.h 1.2 93/07/16 11:51:38 ROOT_DOS Exp $
  629. *    04 Jul 93    1.2        GT    Fix warnings.                                    *
  630. *
  631. *  ATARI Version by David Nash - dnash@chaos.demon.co.uk
  632. *
  633. *  Adjust MSPTICK and add extern int to Tick, Cfunct
  634. *  pause -> Pause to prevent conflict with Lattice C V5.6
  635. *
  636. ****************************************************************************/
  637.  
  638. /* Software timers
  639.  * There is one of these structures for each simulated timer.
  640.  * Whenever the timer is running, it is on a linked list
  641.  * pointed to by "Timers". The list is sorted in ascending order of
  642.  * expiration, with the first timer to expire at the head. This
  643.  * allows the timer process to avoid having to scan the entire list
  644.  * on every clock tick; once it finds an unexpired timer, it can
  645.  * stop searching.
  646.  *
  647.  * Stopping a timer or letting it expire causes it to be removed
  648.  * from the list. Starting a timer puts it on the list at the right
  649.  * place.
  650.  */
  651. struct timer {
  652.     struct timer *next;    /* Linked-list pointer */
  653.     int32 duration;        /* Duration of timer, in ticks */
  654.     int32 expiration;    /* Clock time at expiration */
  655.     void (*func) (void *);    /* Function to call at expiration */
  656.     void *arg;        /* Arg to pass function */
  657.     char state;        /* Timer state */
  658. };
  659. /* Useful user macros that hide the timer structure internals */
  660. volatile extern int Tick;
  661. extern void (*Cfunc[]) (void);    /* List of clock tick functions */
  662. /* In timer.c: */
  663. void alarm (int32 ms);
  664.  
  665. int Pause (int32 ms);
  666. int32 read_timer (struct timer *t);
  667. void set_timer (struct timer *t,int32 x);
  668. void start_timer (struct timer *t);
  669. void stop_timer (struct timer *timer);
  670. char *tformat (int32 t);
  671.  
  672. /* In hardware.c: */
  673. int32 msclock (void);
  674. int32 secclock (void);
  675.  
  676. /*
  677.     -----------------------------------------------------
  678.     ATARI Version by David Nash - dnash@chaos.demon.co.uk
  679.  
  680.     hide definition of tag iface 
  681.     -----------------------------------------------------
  682. */
  683.  
  684. /****************************************************************************
  685. *    $Id: config.h 1.5 93/07/16 11:43:29 ROOT_DOS Exp $
  686. *    20 May 92    1.2        GT    Dial up stuff only.                                *
  687. *    13 Jul 93    1.3        GT    Disable LZW.                                    *
  688. *                            Disable SLIP.                                    *
  689. ****************************************************************************/
  690.  
  691. /****************************************************************************
  692. *
  693. *    ATARI version by David Nash - dnash@chaos.demon.co.uk
  694. *
  695. ****************************************************************************/
  696.  
  697. /* Software options */
  698. /* Software tuning parameters */
  699. /* Hardware driver options */
  700. /****************************************************************************
  701. *    $Id: filter.h 1.2 93/07/16 11:44:39 ROOT_DOS Exp $
  702. *    14 Jun 93    1.2        GT    Enable ip_filter () prototype.                    *
  703. *
  704. *  ATARI Version by David Nash - dnash@chaos.demon.co.uk
  705. *
  706. *  conditionally include ip.h
  707. *
  708. ****************************************************************************/
  709. /*
  710.     -----------------------------------------------------
  711.     ATARI Version by David Nash - dnash@chaos.demon.co.uk
  712.  
  713.     __asm added for lcsum prototype
  714.     -----------------------------------------------------
  715. */
  716.  
  717. /* Global structures and constants pertaining to the interface between IP and
  718.  *     higher level protocols
  719.  */
  720.  
  721. /* IP protocol field values */
  722. /* DoD-style precedences */
  723. /* Amateur-style precedences */
  724. /* Class-of-service bits */
  725. /* IP TOS fields */
  726. /* Pseudo-header for TCP and UDP checksumming */
  727. struct pseudo_header {
  728.     int32 source;        /* IP source */
  729.     int32 dest;        /* IP destination */
  730.     char protocol;        /* Protocol */
  731.     int16 length;        /* Data field length */
  732. };
  733. /* Format of a MIB entry for statistics gathering */
  734. struct mib_entry {
  735.     char *name;
  736.     union {
  737.         int32 integer;
  738.     } value;
  739. };
  740.  
  741. extern char Hashtab[];    /* Modulus lookup table */
  742.  
  743. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  744. extern struct mib_entry Ip_mib[];
  745. /* IP header, INTERNAL representation */
  746. struct ip {
  747.     int32 source;        /* Source address */
  748.     int32 dest;        /* Destination address */
  749.     int16 length;        /* Total length */
  750.     int16 id;        /* Identification */
  751.     int16 offset;        /* Fragment offset in bytes */
  752.     int16 checksum;        /* Header checksum */
  753.  
  754.     struct {
  755.         char congest;    /* Congestion experienced bit (exp) */
  756.         char df;    /* Don't fragment flag */
  757.         char mf;    /* More Fragments flag */
  758.     } flags;
  759.  
  760.     char version;        /* IP version number */
  761.     char tos;        /* Type of service */
  762.     char ttl;        /* Time to live */
  763.     char protocol;        /* Protocol */
  764.     char optlen;        /* Length of options field, bytes */
  765.     char options[40];/* Options field */
  766. };
  767. /* Fields in option type byte */
  768. /* IP option numbers */
  769. /* Timestamp option flags */
  770. /* IP routing table entry */
  771. struct route {
  772.     struct route *prev;    /* Linked list pointers */
  773.     struct route *next;
  774.     int32 target;        /* Target IP address */
  775.     unsigned int bits;    /* Number of significant bits in target */
  776.     int32 gateway;        /* IP address of local gateway for this target */
  777.     int32 metric;        /* Hop count or whatever */
  778.     struct iface *iface;    /* Device interface structure */
  779.     int flags;
  780.     struct timer timer;    /* Time until aging of this entry */
  781.     int32 uses;        /* Usage count */
  782. };
  783. extern struct route *Routes[32][7];    /* Routing table */
  784. extern struct route R_default;            /* Default route entry */
  785.  
  786. /* Cache for the last-used routing entry, speeds up the common case where
  787.  * we handle a burst of packets to the same destination
  788.  */
  789. struct rt_cache {
  790.     int32 target;
  791.     struct route *route;
  792. };
  793. extern struct rt_cache Rt_cache;
  794.  
  795. /* Reassembly descriptor */
  796. struct reasm {
  797.     struct reasm *next;    /* Linked list pointer */
  798.     struct timer timer;    /* Reassembly timeout timer */
  799.     struct frag *fraglist;    /* Head of data fragment chain */
  800.     int16 length;        /* Entire datagram length, if known */
  801.     int32 source;        /* src/dest/id/protocol uniquely describe a datagram */
  802.     int32 dest;
  803.     int16 id;
  804.     char protocol;
  805. };
  806. /* Fragment descriptor in a reassembly list */
  807. struct frag {
  808.     struct frag *prev;    /* Previous fragment on list */
  809.     struct frag *next;    /* Next fragment */
  810.     struct mbuf *buf;    /* Actual fragment data */
  811.     int16 offset;        /* Starting offset of fragment */
  812.     int16 last;        /* Ending offset of fragment */
  813. };
  814. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  815.  
  816. /* Structure for handling raw IP user sockets */
  817. struct raw_ip {
  818.     struct raw_ip *next;    /* Linked list pointer */
  819.  
  820.     struct mbuf *rcvq;    /* receive queue */
  821.     void (*r_upcall) (struct raw_ip *);
  822.     int protocol;        /* Protocol */
  823.     int user;        /* User linkage */
  824. };
  825. extern struct raw_ip *Raw_ip;
  826.  
  827. /* Transport protocol link table */
  828. struct iplink {
  829.     char proto;
  830.     void (*funct) (struct iface *,struct ip *,struct mbuf *,int);
  831. };
  832. extern struct iplink Iplink[];
  833.  
  834. /* In ip.c: */
  835. void ip_garbage (int drastic);
  836.  
  837. (struct iface *iface,struct ip *ip,struct mbuf *bp, int rxbroadcast);
  838.  
  839. (struct iface *iface,struct ip *ip,struct mbuf *bp, int rxbroadcast);
  840.  
  841. (int32 source,int32 dest,char protocol,char tos,char ttl, struct mbuf *bp,int16 length,int16 id,char df);
  842. struct raw_ip *raw_ip (int protocol,void (*r_upcall) (struct raw_ip *) );
  843. void del_ip (struct raw_ip *rrp);
  844.  
  845. /* In iproute.c: */
  846. void ipinit (void);
  847. int16 ip_mtu (int32 addr);
  848.  
  849. (struct mbuf *bp,struct iface *iface,int32 gateway, int prec,int del,int tput,int rel);
  850. int ip_route (struct iface *i_iface,struct mbuf *bp,int rxbroadcast);
  851. int32 locaddr (int32 addr);
  852. void rt_merge (int trace);
  853.  
  854. (int32 target,unsigned int bits,int32 gateway, struct iface *iface,int32 metric,int32 ttl,char private);
  855. int rt_drop (int32 target,unsigned int bits);
  856. struct route *rt_lookup (int32 target);
  857. struct route *rt_blookup (int32 target,unsigned int bits);
  858.  
  859. /* In iphdr.c: */
  860. int16 cksum (struct pseudo_header *ph,struct mbuf *m,int16 len);
  861. int16 eac (int32 sum);
  862. struct mbuf *htonip (struct ip *ip,struct mbuf *data,int cflag);
  863. int ntohip (struct ip *ip,struct mbuf **bpp);
  864.  
  865. /* In either lcsum.c or pcgen.asm: */
  866. int16 __asm lcsum(int16 *wp, int16 len);
  867. /*
  868.  *   Filter entry structure.
  869.  */
  870. struct filter {
  871.     struct filter    *next;        /* Link to next filter element    */
  872.     short        action;        /* Filter entry match action    */
  873.     int        (*type) (struct mbuf *bp, struct ip *ip, struct filter *fp);    /* Packet type comparison f(x)    */
  874.     struct filtersd {
  875.           unsigned long addr;    /* Address used for comparisons    */
  876.         unsigned long mask;    /* Address comparison mask    */
  877.         unsigned char bits;    /* One bits in high part of mask*/
  878.         unsigned char exclude;    /* Exclude matching addresses    */
  879.         unsigned short port;    /* TCP/UDP port (low of range)    */
  880.         unsigned short hiport;    /* High port of range        */
  881.     } src, dest;
  882.     unsigned long    matches;    /* Number of matching packets    */
  883. };
  884.  
  885. int doipfilter ( int argc, char *argv[], void *p );
  886. int ip_filter ( struct mbuf *bp, struct ip *ip, struct filter *fp );
  887.  
  888. /**
  889.  * $Id: setjmp.h,v 1.2 1993/11/14 14:43:52 AGK Rel $
  890.  *
  891.  * ANSI/POSIX.1 non-local jumps
  892.  *
  893.  * (c) Copyright 1992, 1993 HiSoft
  894. **/
  895.  
  896. typedef struct {long __jmp_buf[13];} jmp_buf[1];
  897.  
  898. void (longjmp)(jmp_buf,int);
  899. int (setjmp)(jmp_buf);
  900. typedef struct {long __sigjmp_buf[13 + (sizeof(__sigset_t) / sizeof(long))];} sigjmp_buf[1];
  901.  
  902. void (siglongjmp)(sigjmp_buf, int);
  903. int (sigsetjmp)(sigjmp_buf, int);
  904. /* Kernel process control block */
  905. struct proc {
  906.     struct proc *prev;    /* Process table pointers */
  907.     struct proc *next;    
  908.  
  909.     jmp_buf env;        /* Process state */
  910.     char i_state;        /* Process interrupt state */
  911.  
  912.     unsigned short state;
  913.     void *event;        /* Wait event */
  914.     int16 *stack;        /* Process stack */
  915.     unsigned stksize;    /* Size of same */
  916.     char *name;        /* Arbitrary user-assigned name */
  917.     int retval;        /* Return value from next pwait() */
  918.     struct timer alarm;    /* Alarm clock timer */
  919.     struct mbuf *outbuf;    /* Terminal output buffer */
  920.     int input;        /* standard input socket */
  921.     int output;        /* standard output socket */
  922.     int iarg;        /* Copy of iarg */
  923.     void *parg1;        /* Copy of parg1 */
  924.     void *parg2;        /* Copy of parg2 */
  925.     int freeargs;        /* Free args on termination if set */
  926. };
  927. extern struct proc *Waittab[];    /* Head of wait list */
  928. extern struct proc *Rdytab;    /* Head of ready list */
  929. extern struct proc *Curproc;    /* Currently running process */
  930. extern struct proc *Susptab;    /* Suspended processes */
  931. extern int Stkchk;        /* Stack checking flag */
  932.  
  933. /* In  kernel.c: */
  934. void alert (struct proc *pp,int val);
  935. void chname (struct proc *pp,char *newname);
  936. void killproc (struct proc *pp);
  937. void killself (void);
  938. struct proc *mainproc (char *name);
  939.  
  940. (char *name,unsigned int stksize, void (*pc) (int,void *,void *), int iarg,void *parg1,void *parg2,int freeargs);
  941. int psignal (void *event,int n);
  942. int pwait (void *event);
  943. void resume (struct proc *pp);
  944. void suspend (struct proc *pp);
  945.  
  946. /* In ksubr.c: */
  947. void chkstk (void);
  948. void kinit (void);
  949. unsigned phash (void *event);
  950.  
  951. (struct proc *pp,int iarg,void *parg1,void *parg2, void ((*pc) (int,void *,void *) ) );
  952. /* Stack background fill value for high water mark checking */
  953. /* Value stashed in location 0 to detect null pointer dereferences */
  954. /* Interface encapsulation mode table entry. An array of these structures
  955.  * are initialized in config.c with all of the information necessary
  956.  * to attach a device.
  957.  */
  958.  
  959. struct iface;    /* ATARI incomplete definition to hide definition of tag iface */
  960. struct iftype {
  961.     char *name;        /* Name of encapsulation technique */
  962.     int (*send) (struct mbuf *,struct iface *,int32,int,int,int,int);
  963.                 /* Routine to send an IP datagram */
  964.     int (*output) (struct iface *,char *,char *,int16,struct mbuf *);
  965.                 /* Routine to send link packet */
  966.     char *(*format) (char *,char *);
  967.                 /* Function that formats addresses */
  968.     int (*scan) (char *,char *);
  969.                 /* Reverse of format */
  970.     int type;        /* Type field for network process */
  971.     int hwalen;        /* Length of hardware address, if any */
  972. };
  973. extern struct iftype Iftypes[];
  974.  
  975.  
  976. /* Interface control structure */
  977. struct iface {
  978.     struct iface *next;    /* Linked list pointer */
  979.     char *name;        /* Ascii string with interface name */
  980.  
  981.     int32 addr;        /* IP address */
  982.     int32 broadcast;    /* Broadcast address */
  983.     int32 netmask;        /* Network mask */
  984.  
  985.     int16 mtu;        /* Maximum transmission unit size */
  986.  
  987.     int16 flags;        /* Configuration flags */
  988.     int16 trace;        /* Trace flags */
  989.     char *trfile;        /* Trace file name, if any */
  990.     FILE *trfp;        /* Stream to trace to */
  991.  
  992.     struct iface *forw;    /* Forwarding interface for output, if rx only */
  993.  
  994.     struct proc *rxproc;    /* Receiver process, if any */
  995.     struct proc *txproc;    /* Transmitter process, if any */
  996.     struct proc *supv;    /* Supervisory process, if any */
  997.  
  998.     /* Filter specifications */
  999.     struct filter *infilter;  /* Inbound filter */
  1000.     struct filter *outfilter; /* Outbound filter */
  1001.     /* Device dependant */
  1002.     int dev;        /* Subdevice number to pass to send */
  1003.                 /* To device -- control */
  1004.     int32 (*ioctl) (struct iface *,int cmd,int set,int32 val);
  1005.                 /* From device -- when status changes */
  1006.     int (*iostatus) (struct iface *,int cmd,int32 val);
  1007.                 /* Call before detaching */
  1008.     int (*stop) (struct iface *);
  1009.     char *hwaddr;        /* Device hardware address, if any */
  1010.  
  1011.     /* Encapsulation dependant */
  1012.     void *edv;        /* Pointer to protocol extension block, if any */
  1013.     int type;        /* Link header type for phdr */
  1014.     int xdev;        /* Associated Slip or Nrs channel, if any */
  1015.     struct iftype *iftype;    /* Pointer to appropriate iftype entry */
  1016.  
  1017.             /* Encapsulate an IP datagram */
  1018.     int (*send) (struct mbuf *,struct iface *,int32,int,int,int,int);
  1019.             /* Encapsulate any link packet */
  1020.     int (*output) (struct iface *,char *,char *,int16,struct mbuf *);
  1021.             /* Send raw packet */
  1022.     int (*raw)        (struct iface *,struct mbuf *);
  1023.             /* Display status */
  1024.     void (*show)        (struct iface *);
  1025.  
  1026.     int (*discard)        (struct iface *,struct mbuf *);
  1027.     int (*echo)        (struct iface *,struct mbuf *);
  1028.  
  1029.     /* Counters */
  1030.     int32 ipsndcnt;     /* IP datagrams sent */
  1031.     int32 rawsndcnt;    /* Raw packets sent */
  1032.     int32 iprecvcnt;    /* IP datagrams received */
  1033.     int32 rawrecvcnt;    /* Raw packets received */
  1034.     int32 lastsent;        /* Clock time of last send */
  1035.     int32 lastrecv;        /* Clock time of last receive */
  1036.  
  1037.     /* Demand dial */
  1038.     int    dial_me;        /* !0 means demand dial */
  1039. };
  1040. extern struct iface *Ifaces;    /* Head of interface list */
  1041. extern struct iface  Loopback;    /* Optional loopback interface */
  1042. extern struct iface  Encap;    /* IP-in-IP pseudo interface */
  1043.  
  1044. /* Header put on front of each packet in input queue */
  1045. struct phdr {
  1046.     struct iface *iface;
  1047.     unsigned short type;    /* Use pktdrvr "class" values */
  1048. };
  1049. extern char Noipaddr[];
  1050. extern struct mbuf *Hopper;
  1051.  
  1052. /* In iface.c: */
  1053. struct iface *if_lookup (char *name);
  1054. struct iface *ismyaddr (int32 addr);
  1055. int if_detach (struct iface *ifp);
  1056. int setencap (struct iface *ifp,char *mode);
  1057. char *if_name (struct iface *ifp,char *comment);
  1058. int bitbucket (struct iface *ifp,struct mbuf *bp);
  1059.  
  1060. /* In config.c: */
  1061. int net_route (struct iface *ifp,int type,struct mbuf *bp);
  1062.  
  1063. /* Generic Ethernet constants and templates */
  1064. /* Format of an Ethernet header */
  1065. struct ether {
  1066.     char dest[6];
  1067.     char source[6];
  1068.     int16 type;
  1069. };
  1070. /* Ethernet broadcast address */
  1071. extern char Ether_bdcst[];
  1072.  
  1073. /* Ethernet type fields */
  1074. /* In file enet.c: */
  1075. char *pether (char *out,char *addr);
  1076. int gether (char *out,char *cp);
  1077.  
  1078. (struct mbuf *bp,struct iface *iface,int32 gateway,int prec, int del,int tput,int rel);
  1079.  
  1080. (struct iface *iface,char dest[],char source[],int16 type, struct mbuf *data);
  1081. void eproc (struct iface *iface,struct mbuf *bp);
  1082.  
  1083. /* In enethdr.c: */
  1084. struct mbuf *htonether (struct ether *ether,struct mbuf *data);
  1085. int ntohether (struct ether *ether,struct mbuf **bpp);
  1086.  
  1087. /* Berkeley format socket address structures. These things were rather
  1088.  * poorly thought out, but compatibility is important (or so they say).
  1089.  * Note that all the sockaddr variants must be of the same size, 16 bytes
  1090.  * to be specific. Although attempts have been made to account for alignment
  1091.  * requirements (notably in sockaddr_ax), porters should check each
  1092.  * structure.
  1093.  */
  1094.  
  1095. /* Generic socket address structure */
  1096. struct sockaddr {
  1097.     short sa_family;
  1098.     char sa_data[14];
  1099. };
  1100.  
  1101. /* This is a structure for "historical" reasons (whatever they are) */
  1102. struct in_addr {
  1103.     unsigned long s_addr;
  1104. };
  1105.  
  1106. /* Socket address, DARPA Internet style */
  1107. struct sockaddr_in {
  1108.     short sin_family;
  1109.     unsigned short sin_port;
  1110.     struct in_addr sin_addr;
  1111.     char sin_zero[8];
  1112. };
  1113.  
  1114. /* AX.25 datagram (address) sub-layer definitions */
  1115.  
  1116. /* Upper sub-layer (LAPB) definitions */
  1117.  
  1118. /* Control field templates */
  1119. /* FRMR reason bits */
  1120. /* Per-connection link control block
  1121.  * These are created and destroyed dynamically,
  1122.  * and are indexed through a hash table.
  1123.  * One exists for each logical AX.25 Level 2 connection
  1124.  */
  1125. struct ax25_cb {
  1126.     struct ax25_cb *next;        /* Linked list pointer */
  1127.  
  1128.     struct iface *iface;        /* Interface */
  1129.  
  1130.     struct mbuf *txq;        /* Transmit queue */
  1131.     struct mbuf *rxasm;        /* Receive reassembly buffer */
  1132.     struct mbuf *rxq;        /* Receive queue */
  1133.  
  1134.     char local[7];        /* Addresses */
  1135.     char remote[7];
  1136.  
  1137.     struct {
  1138.         char rejsent;        /* REJ frame has been sent */
  1139.         char remotebusy;    /* Remote sent RNR */
  1140.         char rtt_run;        /* Round trip "timer" is running */
  1141.         char retrans;        /* A retransmission has occurred */
  1142.         char clone;        /* Server-type cb, will be cloned */
  1143.     } flags;
  1144.  
  1145.     char reason;            /* Reason for connection closing */
  1146.     char response;            /* Response owed to other end */
  1147.     char vs;            /* Our send state variable */
  1148.     char vr;            /* Our receive state variable */
  1149.     char unack;            /* Number of unacked frames */
  1150.     int maxframe;            /* Transmit flow control level, frames */
  1151.     int16 paclen;            /* Maximum outbound packet size, bytes */
  1152.     int16 window;            /* Local flow control limit, bytes */
  1153.     char proto;            /* Protocol version */
  1154.     int16 pthresh;            /* Poll threshold, bytes */
  1155.     unsigned retries;        /* Retry counter */
  1156.     unsigned n2;            /* Retry limit */
  1157.     int state;            /* Link state */
  1158.     struct timer t1;        /* Retry timer */
  1159.     struct timer t3;        /* Keep-alive poll timer */
  1160.     int32 rtt_time;            /* Stored clock values for RTT, ticks */
  1161.     int rtt_seq;            /* Sequence number being timed */
  1162.     int32 srt;            /* Smoothed round-trip time, ms */
  1163.     int32 mdev;            /* Mean rtt deviation, ms */
  1164.  
  1165.     void (*r_upcall) (struct ax25_cb *,int);    /* Receiver upcall */
  1166.     void (*t_upcall) (struct ax25_cb *,int);    /* Transmit upcall */
  1167.     void (*s_upcall) (struct ax25_cb *,int,int);    /* State change upcall */
  1168.  
  1169.     int user;            /* User pointer */
  1170.  
  1171.     int segremain;            /* Segmenter state */
  1172. };
  1173. extern struct ax25_cb Ax25default,*Ax25_cb;
  1174. extern char *Ax25states[],*Axreasons[];
  1175. extern int32 Axirtt,T3init,Blimit;
  1176. extern int16 N2,Maxframe,Paclen,Pthresh,Axwindow,Axversion;
  1177.  
  1178. /* In lapb.c: */
  1179. void est_link (struct ax25_cb *axp);
  1180. void lapbstate (struct ax25_cb *axp,int s);
  1181. int lapb_input (struct ax25_cb *axp,int cmdrsp,struct mbuf *bp);
  1182. int lapb_output (struct ax25_cb *axp);
  1183. struct mbuf *segmenter (struct mbuf *bp,int16 ssize);
  1184. int sendctl (struct ax25_cb *axp,int cmdrsp,int cmd);
  1185.  
  1186. /* In lapbtimer.c: */
  1187. void pollthem (void *p);
  1188. void recover (void *p);
  1189.  
  1190. /* In ax25subr.c: */
  1191. int16 ftype (int control);
  1192. void lapb_garbage (int drastic);
  1193.  
  1194. /* Bits within SSID field of AX.25 address */
  1195. /* Our AX.25 address */
  1196. extern char Mycall[7];
  1197.  
  1198. /* List of AX.25 multicast addresses, e.g., "QST   -0" in shifted ASCII */
  1199. extern char Ax25multi[][7];
  1200.  
  1201. extern int Digipeat;
  1202. extern int Ax25mbox;
  1203.  
  1204. /* Number of chars in interface field. The involved definition takes possible
  1205.  * alignment requirements into account, since ax25_addr is of an odd size.
  1206.  */
  1207. /* Socket address, AX.25 style */
  1208. struct sockaddr_ax {
  1209.     short sax_family;        /* 2 bytes */
  1210.     char ax25_addr[7];
  1211.     char iface[(sizeof(struct sockaddr) - sizeof(short) - 7)];        /* Interface name */
  1212. };
  1213.  
  1214. /* Internal representation of an AX.25 header */
  1215. struct ax25 {
  1216.     char dest[7];        /* Destination address */
  1217.     char source[7];        /* Source address */
  1218.     char digis[7][7];    /* Digi string */
  1219.     int ndigis;            /* Number of digipeaters */
  1220.     int nextdigi;            /* Index to next digi in chain */
  1221.     int cmdrsp;            /* Command/response */
  1222. };
  1223.  
  1224. /* C-bit stuff */
  1225. /* AX.25 routing table entry */
  1226. struct ax_route {
  1227.     struct ax_route *next;        /* Linked list pointer */
  1228.     char target[7];
  1229.     char digis[7][7];
  1230.     int ndigis;
  1231.     char type;
  1232. };
  1233. extern struct ax_route *Ax_routes;
  1234. extern struct ax_route Ax_default;
  1235.  
  1236. /* AX.25 Level 3 Protocol IDs (PIDs) */
  1237. /* Link quality report packet header, internal format */
  1238. struct lqhdr {
  1239.     int16 version;        /* Version number of protocol */
  1240.     int32    ip_addr;    /* Sending station's IP address */
  1241. };
  1242. /* Link quality entry, internal format */
  1243. struct lqentry {
  1244.     char addr[7];    /* Address of heard station */
  1245.     int32 count;        /* Count of packets heard from that station */
  1246. };
  1247. /* Link quality database record format
  1248.  * Currently used only by AX.25 interfaces
  1249.  */
  1250. struct lq {
  1251.     struct lq *next;
  1252.     char addr[7];    /* Hardware address of station heard */
  1253.     struct iface *iface;    /* Interface address was heard on */
  1254.     int32 ka9q_time;        /* Time station was last heard */
  1255.     int32 currxcnt;    /* Current # of packets heard from this station */
  1256.  
  1257. };
  1258. extern struct lq *Lq;    /* Link quality record headers */
  1259.  
  1260. /* Structure used to keep track of monitored destination addresses */
  1261. struct ld {
  1262.     struct ld *next;    /* Linked list pointers */
  1263.     char addr[7];/* Hardware address of destination overheard */
  1264.     struct iface *iface;    /* Interface address was heard on */
  1265.     int32 ka9q_time;        /* Time station was last mentioned */
  1266.     int32 currxcnt;    /* Current # of packets destined to this station */
  1267. };
  1268. extern struct ld *Ld;    /* Destination address record headers */
  1269.  
  1270. /* Linkage to network protocols atop ax25 */
  1271. struct axlink {
  1272.     int pid;
  1273.  
  1274. (struct iface *,struct ax25_cb *,char *, char *, struct mbuf *,int);
  1275. };
  1276. extern struct axlink Axlink[];
  1277.  
  1278. /* Codes for the open_ax25 call */
  1279. /* In ax25.c: */
  1280. struct ax_route *ax_add (char *,int,char digis[][7],int);
  1281. int ax_drop (char *);
  1282. struct ax_route *ax_lookup (char *);
  1283. void ax_recv (struct iface *,struct mbuf *);
  1284.  
  1285. (struct mbuf *bp,struct iface *iface,int32 gateway,int prec, int del,int tput,int rel);
  1286.  
  1287. (struct iface *iface,char *dest,char *source,int16 pid, struct mbuf *data);
  1288. int sendframe (struct ax25_cb *axp,int cmdrsp,int ctl,struct mbuf *data);
  1289.  
  1290. (struct iface *iface,struct ax25_cb *axp,char *src, char *dest,struct mbuf *bp,int mcast);
  1291.  
  1292. /* In ax25cmd.c: */
  1293. void st_ax25 (struct ax25_cb *axp);
  1294.  
  1295. /* In axhdr.c: */
  1296. struct mbuf *htonax25 (struct ax25 *hdr,struct mbuf *data);
  1297. int ntohax25 (struct ax25 *hdr,struct mbuf **bpp);
  1298.  
  1299. /* In axlink.c: */
  1300. void getlqentry (struct lqentry *ep,struct mbuf **bpp);
  1301. void getlqhdr (struct lqhdr *hp,struct mbuf **bpp);
  1302. void logsrc (struct iface *iface,char *addr);
  1303. void logdest (struct iface *iface,char *addr);
  1304. char *putlqentry (char *cp,char *addr,int32 count);
  1305. char *putlqhdr (char *cp,int16 version,int32 ip_addr);
  1306. struct lq *al_lookup (struct iface *ifp,char *addr,int sort);
  1307.  
  1308. /* In ax25user.c: */
  1309.  
  1310. (struct iface *,char *,char *, int,int16, void (*) (struct ax25_cb *,int), void (*) (struct ax25_cb *,int), void (*) (struct ax25_cb *,int,int), int user);
  1311. struct mbuf *recv_ax25 (struct ax25_cb *axp,int16 cnt);
  1312. int reset_ax25 (struct ax25_cb *axp);
  1313. int send_ax25 (struct ax25_cb *axp,struct mbuf *bp,int pid);
  1314.  
  1315. /* In ax25subr.c: */
  1316. int addreq (char *a,char *b);
  1317. struct ax25_cb *cr_ax25 (char *addr);
  1318. void del_ax25 (struct ax25_cb *axp);
  1319. struct ax25_cb *find_ax25 (char *);
  1320. char *pax25 (char *e,char *addr);
  1321. int setcall (char *out,char *call);
  1322.  
  1323. /* In socket.c: */
  1324. void beac_input (struct iface *iface,char *src,struct mbuf *bp);
  1325. void s_arcall (struct ax25_cb *axp,int cnt);
  1326. void s_ascall (struct ax25_cb *axp,int old,int new);
  1327. void s_atcall (struct ax25_cb *axp,int cnt);
  1328.  
  1329. /*
  1330.     -----------------------------------------------------
  1331.     ATARI Version by David Nash - dnash@chaos.demon.co.uk
  1332.  
  1333.     Added #define POST and __stdargs upload
  1334.     -----------------------------------------------------
  1335. */
  1336.  
  1337. /**
  1338.  * $Id: stdio.h,v 1.1 1993/11/14 14:43:52 AGK Rel $
  1339.  *
  1340.  * ANSI I/O interface file
  1341.  *
  1342.  * (c) Copyright 1989, 1992, 1993 HiSoft
  1343. **/
  1344.  
  1345. /****************************************************************************
  1346. *    $Id: hardware.h 1.3 93/07/16 11:45:05 ROOT_DOS Exp $
  1347. *    15 Jul 93    1.2        GT    Fix warnings.                                    *
  1348. ****************************************************************************/
  1349.  
  1350. struct stopwatch {
  1351.     long calls;
  1352.     int16 maxval;
  1353.     int16 minval;
  1354. };
  1355. struct screen {
  1356.     char *save;        /* Screen save buffer */
  1357.     int row;        /* Saved cursor location */
  1358.     int col;
  1359. };
  1360. extern struct stopwatch Sw[];
  1361. extern int16 Intstk[];    /* Interrupt stack defined in pcgen.asm */
  1362. extern void (*Shutdown[])();    /* List of functions to call at shutdown */
  1363. extern int Mtasker;    /* Type of multitasker, if any */
  1364.  
  1365. /* In 8250.c: */
  1366. void asytimer (void);
  1367.  
  1368. /* In scc.c: */
  1369. void scctimer (void);
  1370. void sccstop (void);
  1371.  
  1372. /* In pc.c: */
  1373. void newscreen (struct session *sp);
  1374. void freescreen (struct session *sp);
  1375. long bioscnt (void);
  1376. void clrbit (unsigned port,char bits);
  1377. void ctick (void);
  1378. int32 divrem (int32 dividend,int16 divisor);
  1379. void  (*getirq (unsigned int) ) (void);
  1380. int getmask (unsigned irq);
  1381. void ioinit (void);
  1382. void iostop (void);
  1383. void kbint (void);
  1384. int kbread (void);
  1385. int maskoff (unsigned irq);
  1386. int maskon (unsigned irq);
  1387. void pctick (void);
  1388. void setbit (unsigned port,char bits);
  1389. int setirq (unsigned irq,void (*handler) (void));
  1390. void sysreset (void);
  1391. void systick (void);
  1392. void writebit (unsigned port,char mask,int val);
  1393.  
  1394. /* In pcgen.asm: */
  1395. void btick (void);
  1396. void chktasker (void);
  1397. void chtimer (void (*)());
  1398. int32 divrem (int32 dividend,int16 divisor);
  1399. int16 getss (void);
  1400. void giveup (void);
  1401. int kbraw (void);
  1402. int16 longdiv (int16 divisor,int n,int16 *dividend);
  1403. int16 longmul (int16 multiplier,int n,int16 *multiplicand);
  1404. void nullvec (void);
  1405. void uchtimer (void);
  1406. int16 clockbits (void);
  1407.  
  1408. /* In stopwatch.asm: */
  1409. void swstart (void);
  1410. int16 stopval (void);
  1411.  
  1412. /* In sw.c: */
  1413. void swstop (int n);
  1414.  
  1415. /*
  1416.     -----------------------------------------------------
  1417.     ATARI Version by David Nash - dnash@chaos.demon.co.uk
  1418.  
  1419.     Added V_BYTE verbosity level
  1420.     -----------------------------------------------------
  1421. */
  1422.  
  1423. /**
  1424.  * $Id: stdio.h,v 1.1 1993/11/14 14:43:52 AGK Rel $
  1425.  *
  1426.  * ANSI I/O interface file
  1427.  *
  1428.  * (c) Copyright 1989, 1992, 1993 HiSoft
  1429. **/
  1430.  
  1431. /* Definitions common to both FTP servers and clients */
  1432. /* In ftpsubr.c: */
  1433. long sendfile (FILE *fp,int s,int mode,int hash);
  1434. long recvfile (FILE *fp,int s,int mode,int hash);
  1435. int isbinary (FILE *fp);
  1436.  
  1437. /* Per-session FTP client control block */
  1438. struct ftpcli {
  1439.     int control;        /* Control socket */
  1440.     int data;        /* Data socket */
  1441.  
  1442.     char state;
  1443. int16 verbose;                /* Transfer verbosity level */
  1444.     int batch;        /* Command batching flag */
  1445.     int abort;        /* Aborted transfer flag */
  1446.     char type;        /* Transfer type */
  1447.     char typesent;        /* Last type command sent to server */
  1448.     int logbsize;        /* Logical byte size for logical type */
  1449.     FILE *fp;        /* File descriptor being transferred */
  1450.  
  1451.     struct session *session;
  1452. };
  1453. /*
  1454.     -----------------------------------------------------
  1455.     ATARI Version by David Nash - dnash@chaos.demon.co.uk
  1456.  
  1457.     Added __stdargs to tel_output and ttylhandle
  1458.     -----------------------------------------------------
  1459. */
  1460.  
  1461. /* Telnet command characters */
  1462. /* Telnet options */
  1463. /* Telnet protocol control block */
  1464. struct telnet {
  1465.     char local[6];    /* Local option settings */
  1466.     char remote[6];    /* Remote option settings */
  1467.     struct session *session;    /* Pointer to session structure */
  1468.     char eolmode;        /* Control translation of enter key */
  1469. };
  1470. extern int Refuse_echo;
  1471. extern int Tn_cr_mode;
  1472.  
  1473. /* In telnet.c: */
  1474. int tel_connect (struct session *sp,char *fsocket,int len);
  1475.  
  1476. void __stdargs tel_output (int unused, void *p1, void *p2);
  1477. void tnrecv (struct telnet *tn);
  1478. void doopt (struct telnet *tn,int opt);
  1479. void dontopt (struct telnet *tn,int opt);
  1480. void willopt (struct telnet *tn,int opt);
  1481. void wontopt (struct telnet *tn,int opt);
  1482. void answer (struct telnet *tn,int r1,int r2);
  1483.  
  1484. /* In ttylink.c: */
  1485.  
  1486. void __stdargs ttylhandle(int s, void *unused, void *p);
  1487. struct ttystate {
  1488.     struct mbuf *line;    /* Line buffer */
  1489.     int echo;        /* Keyboard local echoing? */
  1490.     int edit;        /* Local editing? */
  1491.     int crnl;        /* Translate cr to lf? */
  1492. };
  1493.  
  1494. /* Session control structure; only one entry is used at a time */
  1495. struct session {
  1496.     int type;
  1497.     char *name;    /* Name of remote host */
  1498.     union {
  1499.         struct ftpcli *ftp;
  1500.         struct telnet *telnet;
  1501.     } cb;
  1502.     struct proc *proc;    /* Primary session process (e.g., tn recv) */
  1503.     struct proc *proc1;    /* Secondary session process (e.g., tn xmit) */
  1504.     struct proc *proc2;    /* Tertiary session process (e.g., upload) */
  1505.     int s;                /* Primary network socket (control for FTP) */
  1506.     FILE *record;        /* Receive record file */
  1507.     char *rfile;        /* Record file name */
  1508.     FILE *upload;        /* Send file */
  1509.     char *ufile;        /* Upload file name */
  1510.     struct ttystate ttystate;
  1511.     struct screen *screen;
  1512.     int input;            /* Input socket */
  1513.     int output;            /* Output socket */
  1514.     int flowmode;        /* control "more" mode */
  1515.     int row;            /* Rows remaining until "more" */
  1516.     int morewait;        /* Output driver is waiting on us */
  1517.     int cur_pos;        /* Cursor position within input buffer */
  1518. };
  1519. extern char *Sestypes[];
  1520. extern unsigned Nsessions;        /* Maximum number of sessions */
  1521. extern struct session *Sessions;    /* Session descriptors themselves */
  1522. extern struct session *Current;        /* Always points to current session */
  1523. extern struct session *Lastcurr;    /* Last non-command session */
  1524. extern struct session *Command;        /* Pointer to command session */
  1525.  
  1526. /* In session.c: */
  1527. void freesession (struct session *sp);
  1528. struct session *sessptr (char *cp);
  1529. struct session *newsession (char *name,int type);
  1530.  
  1531. void __stdargs upload(int unused, void *sp1, void *p);
  1532. /* In pc.c: */
  1533. void swapscreen (struct session *old,struct session *new);
  1534.  
  1535. extern int16 Lport;
  1536. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  1537. extern struct mib_entry Icmp_mib[];
  1538. /* Internet Control Message Protocol */
  1539.  
  1540. /* Message types */
  1541. /* Internal format of an ICMP header (checksum is missing) */
  1542. struct icmp {
  1543.     char type;
  1544.     char code;
  1545.      union icmp_args {
  1546.         int16 mtu;
  1547.         int32 unused;
  1548.         unsigned char pointer;
  1549.         int32 address;
  1550.         struct {
  1551.             int16 id;
  1552.             int16 seq;
  1553.         } echo;
  1554.     } args;
  1555. };
  1556. /* Destination Unreachable codes */
  1557. /* Time Exceeded codes */
  1558. /* Redirect message codes */
  1559. extern int Icmp_trace;
  1560.  
  1561. struct ping {
  1562.     struct session *sp;
  1563.     int32 target;        /* Starting target IP address */
  1564.     int incflag;        /* If true, increment target after each ping */
  1565.     int32 sent;        /* Total number of pings sent */
  1566.     int32 srtt;        /* Smoothed round trip time */
  1567.     int32 mdev;        /* Mean deviation */
  1568.     int32 responses;    /* Total number of responses */
  1569.     int32 interval;        /* Inter-ping interval, ticks */
  1570.     int16 len;        /* Length of data portion of ping */
  1571. };
  1572. /* ICMP messages, decoded */
  1573. extern char *Icmptypes[],*Unreach[],*Exceed[],*Redirect[];
  1574.  
  1575. struct icmplink {
  1576.     char proto;
  1577.     void (*funct) (int32,int32,int32,char,char,struct mbuf **);
  1578. };
  1579. extern struct icmplink Icmplink[];
  1580.  
  1581. /* In icmp.c: */
  1582.  
  1583. (struct iface *iface,struct ip *ip,struct mbuf *bp, int rxbroadcast);
  1584.  
  1585. (struct ip *ip,struct mbuf *data,char type,char code, union icmp_args *args);
  1586.  
  1587. /* In icmpcmd.c: */
  1588. void echo_proc (int32 source,int32 dest,struct icmp *icmp,struct mbuf *bp);
  1589. int pingem (int s,int32 target,int16 seq,int16 id,int16 len);
  1590.  
  1591. /* In icmphdr.c: */
  1592. struct mbuf *htonicmp (struct icmp *icmp,struct mbuf *data);
  1593. int ntohicmp (struct icmp *icmp,struct mbuf **bpp);
  1594.  
  1595. /*
  1596.     -----------------------------------------------------
  1597.     ATARI Version by David Nash - dnash@chaos.demon.co.uk
  1598.  
  1599.     __asm added for lcsum prototype
  1600.     -----------------------------------------------------
  1601. */
  1602.  
  1603. /* Lifetime of a valid ARP entry */
  1604. /* Lifetime of a pending ARP entry */
  1605. /* ARP definitions (see RFC 826) */
  1606.  
  1607. /* Address size definitions */
  1608. /* ARP opcodes */
  1609. /* Hardware types */
  1610. extern char *Arptypes[];    /* Type fields in ASCII, defined in arpcmd */
  1611. /* Table of hardware types known to ARP */
  1612. struct arp_type {
  1613.     int16 hwalen;        /* Hardware length */
  1614.     int16 iptype;        /* Hardware type field for IP */
  1615.     int16 arptype;        /* Hardware type field for ARP */
  1616.     int16 pendtime;        /* # secs to wait pending response */
  1617.     char *bdcst;        /* Hardware broadcast address */
  1618.     char *(*format) (char *,char *);
  1619.                 /* Function that formats addresses */
  1620.     int (*scan) (char *,char *);
  1621.                 /* Reverse of format */
  1622. };
  1623. extern struct arp_type Arp_type[];
  1624. /* Format of an ARP request or reply packet. From p. 3 */
  1625. struct arp {
  1626.     int16 hardware;            /* Hardware type */
  1627.     int16 protocol;            /* Protocol type */
  1628.     char hwalen;            /* Hardware address length, bytes */
  1629.     char pralen;            /* Length of protocol address */
  1630.     int16 opcode;            /* ARP opcode (request/reply) */
  1631.     char shwaddr[255];    /* Sender hardware address field */
  1632.     int32 sprotaddr;        /* Sender Protocol address field */
  1633.     char thwaddr[255];    /* Target hardware address field */
  1634.     int32 tprotaddr;        /* Target protocol address field */
  1635. };
  1636.         
  1637. /* Format of ARP table */
  1638. struct arp_tab {
  1639.     struct arp_tab *next;    /* Doubly-linked list pointers */
  1640.     struct arp_tab *prev;    
  1641.     struct timer timer;    /* Time until aging this entry */
  1642.     struct mbuf *pending;    /* Queue of datagrams awaiting resolution */
  1643.     int32 ip_addr;        /* IP Address, host order */
  1644.     int16 hardware;        /* Hardware type */
  1645.     char state;        /* (In)complete */
  1646.     char pub;        /* Respond to requests for this entry? */
  1647.     char *hw_addr;        /* Hardware address */
  1648. };
  1649. extern struct arp_tab *Arp_tab[];
  1650.  
  1651. struct arp_stat {
  1652.     unsigned recv;        /* Total number of ARP packets received */
  1653.     unsigned badtype;    /* Incoming requests for unsupported hardware */
  1654.     unsigned badlen;    /* Incoming length field(s) didn't match types */
  1655.     unsigned badaddr;    /* Bogus incoming addresses */
  1656.     unsigned inreq;        /* Incoming requests for us */
  1657.     unsigned replies;    /* Replies sent */
  1658.     unsigned outreq;    /* Outoging requests sent */
  1659. };
  1660. extern struct arp_stat Arp_stat;
  1661.  
  1662. /* In arp.c: */
  1663.  
  1664. (int32 ipaddr,int16 hardware,char *hw_addr, int pub);
  1665. void arp_drop (void *p);
  1666.  
  1667. (unsigned int hwtype,int hwalen,int iptype,int arptype, int pendtime,char *bdcst,char *(*format) (char *,char *), int (*scan) (char *,char *) );
  1668. void arp_input (struct iface *iface,struct mbuf *bp);
  1669. struct arp_tab *arp_lookup (int16 hardware,int32 ipaddr);
  1670. char *res_arp (struct iface *iface,int16 hardware,int32 target,struct mbuf *bp);
  1671.  
  1672. /* In arphdr.c: */
  1673. struct mbuf *htonarp (struct arp *arp);
  1674. int ntoharp (struct arp *arp,struct mbuf **bpp);
  1675.  
  1676. static void arp_output (struct iface *iface,int16 hardware,int32 target);
  1677.  
  1678. /* Hash table headers */
  1679. struct arp_tab *Arp_tab[7];
  1680.  
  1681. struct arp_stat Arp_stat;
  1682.  
  1683. /* Resolve an IP address to a hardware address; if not found,
  1684.  * initiate query and return NULLCHAR.  If an address is returned, the
  1685.  * interface driver may send the packet; if NULLCHAR is returned,
  1686.  * res_arp() will have saved the packet on its pending queue,
  1687.  * so no further action (like freeing the packet) is necessary.
  1688.  */
  1689. char *res_arp(
  1690.     struct iface *iface,        /* Pointer to interface block */
  1691.     int16 hardware,            /* Hardware type */
  1692.     int32 target,                /* Target IP address */
  1693.     struct mbuf *bp)            /* IP datagram to be queued if unresolved */
  1694. {
  1695.     register struct arp_tab *arp;
  1696.     struct ip ip;
  1697.  
  1698.     if((arp = arp_lookup(hardware,target)) != (struct arp_tab *)0 && arp->state == 1)
  1699.         return arp->hw_addr;
  1700.     if(arp != (struct arp_tab *)0){
  1701.         /* Earlier packets are already pending, kick this one back
  1702.          * as a source quench
  1703.          */
  1704.         ntohip(&ip,&bp);
  1705.         icmp_output(&ip,bp,4,0,((void *) 0));
  1706.         free_p(bp);
  1707.     } else {
  1708.         /* Create an entry and put the datagram on the
  1709.          * queue pending an answer
  1710.          */
  1711.         arp = arp_add(target,hardware,(char *)0,0);
  1712.         enqueue(&arp->pending,bp);
  1713.         arp_output(iface,hardware,target);
  1714.     }
  1715.     return (char *)0;
  1716. }
  1717. /* Handle incoming ARP packets. This is almost a direct implementation of
  1718.  * the algorithm on page 5 of RFC 826, except for:
  1719.  * 1. Outgoing datagrams to unresolved addresses are kept on a queue
  1720.  *    pending a reply to our ARP request.
  1721.  * 2. The names of the fields in the ARP packet were made more mnemonic.
  1722.  * 3. Requests for IP addresses listed in our table as "published" are
  1723.  *    responded to, even if the address is not our own.
  1724.  */
  1725. void
  1726. arp_input(iface,bp)
  1727. struct iface *iface;
  1728. struct mbuf *bp;
  1729. {
  1730.     struct arp arp;
  1731.     struct arp_tab *ap;
  1732.     struct arp_type *at;
  1733.     int i;
  1734.     
  1735.     Arp_stat.recv++;
  1736.     if(ntoharp(&arp,&bp) == -1)    /* Convert into host format */
  1737.         return;
  1738.     if(arp.hardware >= 9){
  1739.         /* Unknown hardware type, ignore */
  1740.         Arp_stat.badtype++;
  1741.         return;
  1742.     }
  1743.     at = &Arp_type[arp.hardware];
  1744.     if(arp.protocol != at->iptype){
  1745.         /* Unsupported protocol type, ignore */
  1746.         Arp_stat.badtype++;
  1747.         return;
  1748.     }
  1749.     if(/*uchar(arp.hwalen) > MAXHWALEN ||*/ ((unsigned char)(arp.pralen)) != sizeof(int32)){
  1750.         /* Incorrect protocol addr length (different hw addr lengths
  1751.          * are OK since AX.25 addresses can be of variable length)
  1752.          */
  1753.         Arp_stat.badlen++;
  1754.         return;
  1755.     }
  1756.     if(__builtin_memcmp(arp.shwaddr,at->bdcst,at->hwalen) == 0){
  1757.         /* This guy is trying to say he's got the broadcast address! */
  1758.         Arp_stat.badaddr++;
  1759.         return;
  1760.     }
  1761.     /* If this guy is already in the table, update its entry
  1762.      * unless it's a manual entry (noted by the lack of a timer)
  1763.      */
  1764.     ap = (struct arp_tab *)0;    /* ap plays the role of merge_flag in the spec */
  1765.     if((ap = arp_lookup(arp.hardware,arp.sprotaddr)) != (struct arp_tab *)0 
  1766.      && ((&ap->timer)->duration* 20) != 0){
  1767.         ap = arp_add(arp.sprotaddr,arp.hardware,arp.shwaddr,0);
  1768.     }
  1769.     /* See if we're the address they're looking for */
  1770.     if(ismyaddr(arp.tprotaddr) != (struct iface *)0){
  1771.         if(ap == (struct arp_tab *)0)    /* Only if not already in the table */
  1772.             arp_add(arp.sprotaddr,arp.hardware,arp.shwaddr,0);
  1773.  
  1774.         if(arp.opcode == 1){
  1775.             /* Swap sender's and target's (us) hardware and protocol
  1776.              * fields, and send the packet back as a reply
  1777.              */
  1778.             __builtin_memcpy(arp.thwaddr,arp.shwaddr,(int16)((unsigned char)(arp.hwalen)));
  1779.             /* Mark the end of the sender's AX.25 address
  1780.              * in case he didn't
  1781.              */
  1782.             if(arp.hardware == 3)
  1783.                 arp.thwaddr[((unsigned char)(arp.hwalen))-1] |= 0x01;
  1784.  
  1785.             __builtin_memcpy(arp.shwaddr,iface->hwaddr,at->hwalen);
  1786.             arp.tprotaddr = arp.sprotaddr;
  1787.             arp.sprotaddr = iface->addr;
  1788.             arp.opcode = 2;
  1789.             if((bp = htonarp(&arp)) == (struct mbuf *)0)
  1790.                 return;
  1791.  
  1792.             if(iface->forw != (struct iface *)0)
  1793.                 (*iface->forw->output)(iface->forw,
  1794.                  arp.thwaddr,iface->forw->hwaddr,at->arptype,bp);
  1795.             else 
  1796.                 (*iface->output)(iface,arp.thwaddr,
  1797.                  iface->hwaddr,at->arptype,bp);
  1798.             Arp_stat.inreq++;
  1799.         } else {
  1800.             Arp_stat.replies++;
  1801.         }
  1802.     } else if(arp.opcode == 1 
  1803.      && (ap = arp_lookup(arp.hardware,arp.tprotaddr)) != (struct arp_tab *)0 
  1804.      && ap->pub){
  1805.         /* Otherwise, respond if the guy he's looking for is
  1806.          * published in our table.
  1807.          */
  1808.         __builtin_memcpy(arp.thwaddr,arp.shwaddr,(int16)((unsigned char)(arp.hwalen)));
  1809.         __builtin_memcpy(arp.shwaddr,ap->hw_addr,at->hwalen);
  1810.         arp.tprotaddr = arp.sprotaddr;
  1811.         arp.sprotaddr = ap->ip_addr;
  1812.         arp.opcode = 2;
  1813.         if((bp = htonarp(&arp)) == (struct mbuf *)0)
  1814.             return;
  1815.         if(iface->forw != (struct iface *)0)
  1816.             (*iface->forw->output)(iface->forw,
  1817.              arp.thwaddr,iface->forw->hwaddr,at->arptype,bp);
  1818.         else 
  1819.             (*iface->output)(iface,arp.thwaddr,
  1820.              iface->hwaddr,at->arptype,bp);
  1821.         Arp_stat.inreq++;
  1822.     } else if(arp.opcode == 3){
  1823.         for(i=0;i< 7;i++)
  1824.             for(ap = Arp_tab[i];ap != (struct arp_tab *)0;ap = ap->next)
  1825.                 if(__builtin_memcmp(ap->hw_addr,arp.thwaddr,at->hwalen) == 0)
  1826.                     goto found;
  1827.     found:    if(ap != (struct arp_tab *)0 && ap->pub){
  1828.             __builtin_memcpy(arp.shwaddr,iface->hwaddr,at->hwalen);
  1829.             arp.tprotaddr = ap->ip_addr;
  1830.             arp.sprotaddr = iface->addr;
  1831.             arp.opcode = 4;
  1832.             if((bp = htonarp(&arp)) == (struct mbuf *)0)
  1833.                 return;
  1834.             if(iface->forw != (struct iface *)0)
  1835.                 (*iface->forw->output)(iface->forw,
  1836.                  arp.thwaddr,iface->forw->hwaddr,0x8035,bp);
  1837.             else 
  1838.                 (*iface->output)(iface,arp.thwaddr,
  1839.                  iface->hwaddr,0x8035,bp);
  1840.             Arp_stat.inreq++;
  1841.         }
  1842.     }
  1843. }
  1844. /* Add an IP-addr / hardware-addr pair to the ARP table */
  1845. struct arp_tab *arp_add(
  1846.     int32 ipaddr,                /* IP address, host order */
  1847.     int16 hardware,            /* Hardware type */
  1848.     char *hw_addr,                /* Hardware address, if known; NULLCHAR otherwise */
  1849.     int pub)                        /* Publish this entry? */
  1850. {
  1851.     struct mbuf *bp;
  1852.     register struct arp_tab *ap;
  1853.     struct arp_type *at;
  1854.     unsigned hashval;
  1855.  
  1856.     if(hardware >= 9)
  1857.         return (struct arp_tab *)0;    /* Invalid hardware type */
  1858.     at = &Arp_type[hardware];
  1859.  
  1860.     if((ap = arp_lookup(hardware,ipaddr)) == (struct arp_tab *)0){
  1861.         /* New entry */
  1862.         ap = (struct arp_tab *)callocw(1,sizeof(struct arp_tab));
  1863.         ap->hw_addr = mallocw(at->hwalen);
  1864.         ap->timer.func = arp_drop;
  1865.         ap->timer.arg = ap;
  1866.         ap->hardware = hardware;
  1867.         ap->ip_addr = ipaddr;
  1868.  
  1869.         /* Put on head of hash chain */
  1870.         hashval = hash_ip(ipaddr);
  1871.         ap->prev = (struct arp_tab *)0;
  1872.         ap->next = Arp_tab[hashval];
  1873.         Arp_tab[hashval] = ap;
  1874.         if(ap->next != (struct arp_tab *)0){
  1875.             ap->next->prev = ap;
  1876.         }
  1877.     }
  1878.     if(hw_addr == (char *)0){
  1879.         /* Await response */
  1880.         ap->state = 0;
  1881.         set_timer(&ap->timer,Arp_type[hardware].pendtime * 1000L);
  1882.     } else {
  1883.         /* Response has come in, update entry and run through queue */
  1884.         ap->state = 1;
  1885.         set_timer(&ap->timer,900 *1000L);
  1886.         __builtin_memcpy(ap->hw_addr,hw_addr,at->hwalen);
  1887.         ap->pub = pub;
  1888.         while((bp = dequeue(&ap->pending)) != (struct mbuf *)0)
  1889.             ip_route((struct iface *)0,bp,0);
  1890.     }
  1891.     start_timer(&ap->timer);
  1892.     return ap;
  1893. }
  1894.  
  1895. /* Remove an entry from the ARP table */
  1896. void
  1897. arp_drop(p)
  1898. void *p;
  1899. {
  1900.     register struct arp_tab *ap;
  1901.  
  1902.     ap = (struct arp_tab *)p;
  1903.     if(ap == (struct arp_tab *)0)
  1904.         return;
  1905.     stop_timer(&ap->timer);    /* Shouldn't be necessary */
  1906.     if(ap->next != (struct arp_tab *)0)
  1907.         ap->next->prev = ap->prev;
  1908.     if(ap->prev != (struct arp_tab *)0)
  1909.         ap->prev->next = ap->next;
  1910.     else
  1911.         Arp_tab[hash_ip(ap->ip_addr)] = ap->next;
  1912.     free_q(&ap->pending);
  1913.     free(ap->hw_addr);
  1914.     free((char *)ap);
  1915. }
  1916.  
  1917. /* Look up the given IP address in the ARP table */
  1918. struct arp_tab * arp_lookup(
  1919.     int16 hardware,
  1920.     int32 ipaddr)
  1921. {
  1922.     register struct arp_tab *ap;
  1923.  
  1924.     for(ap = Arp_tab[hash_ip(ipaddr)]; ap != (struct arp_tab *)0; ap = ap->next){
  1925.         if(ap->ip_addr == ipaddr && ap->hardware == hardware)
  1926.             break;
  1927.     }
  1928.     return ap;
  1929. }
  1930. /* Send an ARP request to resolve IP address target_ip */
  1931. static void arp_output(
  1932.     struct iface *iface,
  1933.     int16 hardware,
  1934.     int32 target)
  1935. {
  1936.     struct arp arp;
  1937.     struct mbuf *bp;
  1938.     struct arp_type *at;
  1939.  
  1940.     at = &Arp_type[hardware];
  1941.     if(iface->output == (int (*)())0)
  1942.         return;
  1943.     
  1944.     arp.hardware = hardware;
  1945.     arp.protocol = at->iptype;
  1946.     arp.hwalen = at->hwalen;
  1947.     arp.pralen = sizeof(int32);
  1948.     arp.opcode = 1;
  1949.     __builtin_memcpy(arp.shwaddr,iface->hwaddr,at->hwalen);
  1950.     arp.sprotaddr = iface->addr;
  1951.     __builtin_memset(arp.thwaddr,0,at->hwalen);
  1952.     arp.tprotaddr = target;
  1953.     if((bp = htonarp(&arp)) == (struct mbuf *)0)
  1954.         return;
  1955.     (*iface->output)(iface,at->bdcst,
  1956.         iface->hwaddr,at->arptype,bp);
  1957.     Arp_stat.outreq++;
  1958. }
  1959.  
  1960.